/**
 * 
 */
package org.wolf.core.schema;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 何小锋
 * 
 */
public class IndexSchema implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 字段类型
	 */
	private Map<String, FieldType> fieldTypes = new HashMap<String, FieldType>();

	/**
	 * 字段
	 */
	private Map<String, DocField> fields = new HashMap<String, DocField>();

	/**
	 * 复制字段
	 */
	private List<CopyField> copyFields = new ArrayList<CopyField>();

	/**
	 * 唯一字段
	 */
	private String uniqueField;

	/**
	 * 默认搜索字段
	 */
	private String defaultField;

	/**
	 * 默认操作符（OR|AND)
	 */
	private String defaultOperator = "OR";

	public void addFieldType(String name, FieldType fieldType) {
		if (fieldType == null || name == null)
			return;
		fieldTypes.put(name, fieldType);
	}

	public void addField(DocField field) {
		if (field == null)
			return;
		fields.put(field.getName(), field);
	}

	public void addCopyField(CopyField copyField) {
		if (copyField == null || copyField.getSource() == null
				|| copyField.getTarget() == null)
			return;
		for (CopyField cf : copyFields) {
			if (cf.getSource().equals(copyField.getSource())
					&& cf.getTarget().equals(copyField.getTarget()))
				return;
		}
		copyFields.add(copyField);
	}

	public String getUniqueField() {
		return uniqueField;
	}

	public void setUniqueField(String uniqueField) {
		this.uniqueField = uniqueField;
	}

	public String getDefaultField() {
		return defaultField;
	}

	public void setDefaultField(String defaultField) {
		this.defaultField = defaultField;
	}

	public String getDefaultOperator() {
		return defaultOperator;
	}

	public void setDefaultOperator(String defaultOperator) {
		this.defaultOperator = defaultOperator;
	}

}
